<template>
  <div class="xtx-checkbox" @click="data=!data">
    <i v-if="data" class="iconfont icon-checked"></i>
    <i v-else class="iconfont icon-unchecked"></i>
    <span v-if="$slots.default">
      <slot />
    </span>
  </div>
</template>
<script>
// import { ref } from 'vue'
import { useVModel } from '@vueuse/core'

export default {
  name: 'XtxCheckbox',
  props: {
    modelValue: {
      type: Boolean,
      // required: true
      default: true
    }
  },
  setup (props, { emit }) {
    // 基于第三方的方法简化父子传值
    const data = useVModel(props, 'modelValue', emit)
    // const checked = ref(false)
    // const changeChecked = () => {
    //   // checked.value = !checked.value
    //   // emit('update:modelValue', !props.modelValue)
    //   data.value = !data.value
    // }
    return { data }
  }
}
</script>
<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
